package com.feng.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.feng.properties.JdbcPropertiies;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;


/**
 * @author : lrf
 * @description :
 * @tip :
 * @date : 2019/3/10
 */
@Configuration
@EnableConfigurationProperties(JdbcPropertiies.class)
public class JdbcConfig {

    @Bean
    public DataSource dataSource(JdbcPropertiies prop){
        DruidDataSource source = new DruidDataSource();
        source.setDriverClassName(prop.getDriverClassName());
        source.setUrl(prop.getUrl());
        source.setUsername(prop.getUsername());
        source.setPassword(prop.getPassword());
        return source;
    }

    /**
     * 说明：
     * 也可使用属性注入方式进行注入
     */
//    @Autowired
//    private JdbcProperties jdbcProperties;
    /**
     * 说明：
     * 也可使用构造方式进行注入
     */
//    public JdbcConfig(JdbcProperties prop) {
//        this.jdbcProperties = prop;
//    }
}
